﻿using DevelopAssistant.AddIn;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DevelopAssistant.AddIn.Screenshot
{
    public partial class MainForm : ICSharpCode.WinFormsUI.Forms.BaseForm
    {
        protected bool h;
        protected int x1;
        protected int y1;
        protected int x2;
        protected int y2; 

        private ProfessionalCaptureImageToolColorTable _colorTable =
        new ProfessionalCaptureImageToolColorTable();

        public Form HostForm;

        public MainForm()
        {
            h = false;
            InitializeComponent();
        }

        public MainForm(Form HostWindow, WindowAddIn AddIn)
            : this()
        {
            this.HostForm = HostWindow;
            this.ShowInTaskbar = false;
            this.TopMost = true;
            this.XTheme = ((ICSharpCode.WinFormsUI.Forms.BaseForm)HostWindow).XTheme;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            if (h) HostForm.Location = new Point(x1, y1);  
        }

        private void BtnScreenshot_Click(object sender, EventArgs e)
        {
            x2 = this.Location.X;
            y2 = this.Location.Y;
            this.Location = new Point(-this.Width - 20, -this.Height - 20);

            CaptureImageTool capture = new CaptureImageTool();
            capture.ColorTable = _colorTable;
            capture.SelectCursor = CursorManager.ArrowNew;
            capture.DrawCursor = CursorManager.CrossNew;


            if (DialogResult.OK.Equals(capture.ShowDialog()))
            {
                this.toolStripLabel3.Text = "完成";
                this.Preview.Image = capture.Image;
            }

            this.Location = new Point(x2, y2);           

        }

        private void BtnHideAssistant_Click(object sender, EventArgs e)
        {
            x1 = HostForm.Location.X;
            y1 = HostForm.Location.Y;
            HostForm.Location = new Point(-HostForm.Width - 20, -HostForm.Height - 20);
            h = true;
        }

        private void toolStripButtonDrag_Click(object sender, EventArgs e)
        {
            this.Preview.SetDrag();
            if (this.Preview.Drag)
                toolStripButtonDrag.Checked = true;
            else
                toolStripButtonDrag.Checked = false;
        }

        private void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            this.Preview.SaveToFile();
        }

    }
}
